{% extends 'contact.html' %}
{% block body %}

    <div style="width: 50%;
    height: 202px;
    margin: 89px auto;">
        <div class="form-group ">
            <label for="exampleInputEmail1">请输入新密码</label>
            <input type="password" class="form-control" id="New_Password" placeholder="New_Password">
        </div>
        <div class="form-group ">
            <label for="exampleInputPassword1">请再次确认密码</label>
            <input type="password" class="form-control" id="Repeat_Password" placeholder="Repeat_Password">
        </div>

        <button type="button" id="sumbit" class="layui-btn layui-btn-lg layui-btn-normal"
                style="margin: 0 40%;width: 200px">提交
        </button>
    </div>
    <script>
        //定义一个函数
        function sleep() {
            window.location.reload();
        }

        $('#sumbit').click(function () {
            let New_Password = $('#New_Password').val();
            let Repeat_Password = $('#Repeat_Password').val();
            let user = '{{ request.session.user }}';

            if (New_Password & Repeat_Password) {
                if (New_Password == Repeat_Password) {
                    $.ajax({
                        url: "{% url 'myadmin:Check_Password' %}",//路径
                        type: "post", //提交方式
                        data: {'New_Password': New_Password, 'user': user},
                        success: function (result) {
                            if (result.code = 200) {
                                layer.msg("修改成功！");
                                setTimeout(sleep, 1200);
                            }
                        },
                        error: function (error) {
                            layer.msg("500，请稍后尝试")
                        }
                    })
                } else {
                    xtalert.alertErrorToast("小主,两次输入的密码不一致")
                }
            } else {
                xtalert.alertErrorToast("小主,密码不能为空");
            }
        })
    </script>
{% endblock %}

